package cl.uchile.sti.authorization.dao;

import cl.uchile.sti.authorization.model.Modulo;

import javax.persistence.EntityManager;

/**
 * Created with IntelliJ IDEA.
 * User: Julio Villane
 * Date: 12-12-12
 * Time: 08:51 AM
 */
public class ModuloDAO {

    private static EntityManager entityManager = cambiarPorSpring.getEntityManager();

    private ModuloDAO(){ }

    public static Modulo find(Long id){
        return entityManager.find(Modulo.class, id);
    }

    public static Modulo save(Modulo modulo) {
        if (modulo.getId() == null) {
            entityManager.persist(modulo);
            return modulo;
        } else {
            return entityManager.merge(modulo);
        }
    }

    public static void delete(Modulo modulo){
        entityManager.remove(modulo);
    }
}
